package com.cloud.common.exception;

import com.cloud.common.domain.DefaultResult;
import com.cloud.common.exception.enums.CloudErrorEnum;
import com.cloud.common.exception.enums.ErrorEnum;

/**
 * CloudException
 *
 * @author wangjian
 * @create 2020/10/07 13:54
 * @description Service层抛出异常自定义异常
 */
public class CloudException extends RuntimeException {
    private static final long serialVersionUID = 1L;
    private String msg;
    private int code = 500;

    public CloudException() {
        super(ErrorEnum.UNKNOWN.getMsg());
        this.msg = ErrorEnum.UNKNOWN.getMsg();
    }


    public CloudException(CloudErrorEnum eEnum, Throwable e) {
        super(eEnum.getMsg(), e);
        this.msg = eEnum.getMsg();
        this.code = eEnum.getCode();
    }

    public CloudException(CloudErrorEnum eEnum) {
        super(eEnum.getMsg());
        this.msg = eEnum.getMsg();
        this.code = eEnum.getCode();
    }

    public CloudException(CloudErrorEnum eEnum, String msg) {
        super(msg);
        this.msg = msg;
        this.code = eEnum.getCode();
    }

    public CloudException(String exception) {
        super(exception);
        this.msg = exception;
    }

    public CloudException(DefaultResult result) {
        super(result.getMsg());
        this.msg = result.getMsg();
        this.code = result.getCode();
    }

    public CloudException(String msg, int code) {
        super(msg);
        this.msg = msg;
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }


    public void setMsg(String msg) {
        this.msg = msg;
    }


    public int getCode() {
        return code;
    }


    public void setCode(int code) {
        this.code = code;
    }

}
